#include "stdafx.h"

#include "../../loader.h"
using namespace dlguif;

#include <iostream>
using std::cout;
using std::cerr;
using std::endl;

Loader loader;
void* ppm = NULL;

void CALLBACK  OnGui(void* user_context, const callback_info* ci)
{
	static int count = 0;
	count ++;

	Loader* ploader = (Loader*)user_context;

	cout << "GUI event! " << count << endl;
	cout << "tag: " << ci->tag << endl;
	cout << "type: " << Loader::event_type_to_string(ci->eventType) << endl;
	cout << "Param1: " << ci->param1 <<  endl;
	cout << "Param2: " << ci->param2 <<  endl;
	cout << "Class name: " << ci->class_name << endl;
	cout << "Name: " << ci->name << endl;
	cout << "--------------------------" << endl;

	if(ci->eventType == EVENT_TYPE_FORM_CLICK)
	{
		ploader->PopupMenuPopup(ppm, 100, 100);
	}
}



int _tmain(int argc, _TCHAR* argv[])
{
	{

		//Loader loader; //(L"j:/dlguif/dlguif/delphi_dll_project/dlguif.dll");
		loader.SetGuiEventCallBack(OnGui, (void*)&loader );

		void* pform = loader.CreateForm( "caption", "form", 10, 10, 800, 600 );
		 ppm = loader.CreatePopupMenu(pform, "mypopup");
		loader.CreatePopupMenuItem(ppm, NULL, "popup item");
		loader.CreatePopupMenuItem(ppm, NULL, "popup item");
		loader.CreatePopupMenuItem(ppm, NULL, "popup item");
		loader.CreatePopupMenuItem(ppm, NULL, "popup item");
		loader.CreatePopupMenuItem(ppm, NULL, "popup item");
		loader.SetControlPopupMenu(pform, ppm);
		loader.ShowForm(pform);
		loader.Run();

		/*
		while( loader.ProcessMessages() )
		{
			if(!loader.GetControlVisible(pform))
			{
				//loader.Terminate();
				break;
			}


			Sleep(1);
		}
		*/

	   int end =0;
	}


	return 0;
}
